using System.Collections;
using Holoville.HOTween;
using I2.Loc;
using UnityEngine;

public class MarketVehicleUpgradeButton : MonoBehaviour
{
	public UIWidget holder;

	public UISprite buttonSprite;

	public UILabel title;

	private Product productToBuy;

	private void OnClick()
	{
		MarketControllerUI.instance.productsPanel.productInfoPanel.ShowInfoPanel();
		MarketControllerUI.instance.mainButtons.SetMainButtons();
	}

	private void OnEnable()
	{
		CoroutineRunner.Instance.StartCoroutine(FadeIn());
	}

	private IEnumerator FadeIn()
	{
		holder.alpha = 0f;
		HOTween.To(holder, 0.25f, new TweenParms().Prop("alpha", 1f).UpdateType(UpdateType.TimeScaleIndependentUpdate));
		yield return CoroutineRunner.WaitForSeconds(0.26f);
		holder.alpha = 1f;
	}

	public void SetButton()
	{
		if (!MarketControllerUI.instance.selectedProduct.Purchased)
		{
			holder.gameObject.SetActive(false);
		}
		else if (MarketControllerUI.instance.selectedProduct.IsVehicle && MarketController.Instance.HaveCarUpgrades(MarketControllerUI.instance.selectedProduct.id))
		{
			productToBuy = MarketControllerUI.instance.selectedProduct;
			SetButtonUpgradeCar();
		}
		else
		{
			holder.gameObject.SetActive(false);
		}
	}

	private void SetButtonUpgradeCar()
	{
		if (productToBuy is ProductCar && productToBuy.Purchased && MarketController.Instance.AllUpgradesAreBuyed(productToBuy.id))
		{
			holder.gameObject.SetActive(false);
			return;
		}
		holder.gameObject.SetActive(true);
		string text = ScriptLocalization.Get("Market/itemUpgrade");
		title.text = ((!string.IsNullOrEmpty(text)) ? text : "Нет локализации");
	}
}
